package cn.ds.assets.module.assets.dal.mysql.dataQualityRuleSetValue;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.dataQualityRuleSetValue.BaseDataQualityRuleSetValueDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.dataQualityRuleSetValue.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 数据质量规则设置值 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseDataQualityRuleSetValueMapper extends BaseMapperX<BaseDataQualityRuleSetValueDO> {

    default PageResult<BaseDataQualityRuleSetValueDO> selectPage(BaseDataQualityRuleSetValuePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseDataQualityRuleSetValueDO>()
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getValue, reqVO.getValue())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getQualityRuleSetId, reqVO.getQualityRuleSetId())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getQualityRuleId, reqVO.getQualityRuleId())
                .betweenIfPresent(BaseDataQualityRuleSetValueDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getRuleCondition, reqVO.getRuleCondition())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getUnit, reqVO.getUnit())
                .inIfPresent(BaseDataQualityRuleSetValueDO::getId,reqVO.getIds())
                .orderByDesc(BaseDataQualityRuleSetValueDO::getId));
    }

    default List<BaseDataQualityRuleSetValueDO> selectList(BaseDataQualityRuleSetValueExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseDataQualityRuleSetValueDO>()
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getValue, reqVO.getValue())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getQualityRuleSetId, reqVO.getQualityRuleSetId())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getQualityRuleId, reqVO.getQualityRuleId())
                .betweenIfPresent(BaseDataQualityRuleSetValueDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getRuleCondition, reqVO.getRuleCondition())
                .eqIfPresent(BaseDataQualityRuleSetValueDO::getUnit, reqVO.getUnit())
                .inIfPresent(BaseDataQualityRuleSetValueDO::getId,reqVO.getIds())
                .orderByDesc(BaseDataQualityRuleSetValueDO::getId));
    }

    @Update("UPDATE assets_data_quality_rule_set_value SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
